//
//  Index_detailViewController.m
//  e家园设计
//
//  Created by lanou on 15/4/14.
//  Copyright (c) 2015年 lanou3g.com. All rights reserved.
//

#import "Index_detailViewController.h"
@interface Index_detailViewController ()<UIScrollViewDelegate>
{
    UIScrollView *_scroll;
    UILabel *_numLable;
}
@property (nonatomic, retain)UIScrollView *lunboScroll;
@end

@implementation Index_detailViewController
- (void)dealloc
{
    [_lunboScroll release];
    [_dic release];
    [_actDic release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}


#pragma mark -
#pragma mark 轮播图
- (void)createLunBo
{
    self.lunboScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 240)];
    [self.view addSubview:self.lunboScroll];
    NSArray *arr = self.dic[@"imageUrl"];
    self.lunboScroll.contentSize = CGSizeMake(self.view.frame.size.width * arr.count, 0);
    self.lunboScroll.delegate = self;
    self.lunboScroll.pagingEnabled = YES;
    for (int i = 0; i < arr.count; i++) {
        NSURL *url = arr[i];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * self.lunboScroll.frame.size.width, 0, self.lunboScroll.frame.size.width, self.lunboScroll.frame.size.height)];
        [self.lunboScroll addSubview:imageView];
        [imageView sd_setImageWithURL:url];
    }
    _numLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
    [self.view addSubview:_numLable];
    _numLable.textAlignment = NSTextAlignmentCenter;
    _numLable.text = [NSString stringWithFormat:@"%d/%ld", 1, [self.dic[@"imageUrl"] count]];
}
// 协议方法
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView == self.lunboScroll) {
        NSInteger num = scrollView.contentOffset.x / scrollView.frame.size.width;
        _numLable.text = [NSString stringWithFormat:@"%ld/%ld", num + 1, [self.dic[@"imageUrl"] count]];
    }
}

#pragma mark -
#pragma mark 创建轮播图下方View

- (void)createView
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(-self.view.frame.size.width * 3.5, 220, self.view.frame.size.width * 8, self.view.frame.size.width * 8)];
    [self.view addSubview:view];
    [view release];
    view.layer.cornerRadius = self.view.frame.size.width * 4;
    view.layer.masksToBounds = YES;
    [view setBackgroundColor:[UIColor whiteColor]];
}
- (void)createMiddleView
{
    UIView  *view = [[UIView alloc] initWithFrame:CGRectMake(0, 240, self.view.frame.size.width, 140)];
    [self.view addSubview:view];
    [view release];
    
    UILabel *upLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, view.frame.size.width, 30)];
    [view addSubview:upLable];
    [upLable release];
    upLable.textAlignment = NSTextAlignmentCenter;
    upLable.text = self.dic[@"name"];
    
    UIImageView *image1 = [[UIImageView alloc] initWithFrame:CGRectMake(view.frame.size.width / 8 - 20, 50, 40, 40)];
    image1.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"iconfont-huxing" ofType:@"png"]];
    [view addSubview:image1];
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 90, view.frame.size.width / 4, 40)];
    [view addSubview:label1];
    [label1 release];
    label1.textColor = [UIColor lightGrayColor];
    [label1 setFont:[UIFont systemFontOfSize:15.0]];
    label1.textAlignment = NSTextAlignmentCenter;
    label1.text = self.dic[@"houseType"];
    
    UIImageView *image2 = [[UIImageView alloc] initWithFrame:CGRectMake(view.frame.size.width / 8 * 3 - 20, 50, 40, 40)];
    image2.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"iconfont-fengge" ofType:@"png"]];
    [view addSubview:image2];
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(view.frame.size.width / 4, 90, view.frame.size.width / 4, 40)];
    [view addSubview:label2];
    [label2 release];
    label2.textColor = [UIColor lightGrayColor];
    [label2 setFont:[UIFont systemFontOfSize:15.0]];
    label2.textAlignment = NSTextAlignmentCenter;
    label2.text = self.dic[@"style"];
    
    UIImageView *image3 = [[UIImageView alloc] initWithFrame:CGRectMake(view.frame.size.width / 8 * 5 - 20, 50, 40, 40)];
    image3.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"iconfont-i5" ofType:@"png"]];
    [view addSubview:image3];
    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(view.frame.size.width / 4 * 2, 90, view.frame.size.width / 4, 40)];
    [view addSubview:label3];
    [label3 release];
    label3.textColor = [UIColor lightGrayColor];
    [label3 setFont:[UIFont systemFontOfSize:15.0]];
    label3.textAlignment = NSTextAlignmentCenter;
    label3.text = self.dic[@"space"];
    
    UIImageView *image4 = [[UIImageView alloc] initWithFrame:CGRectMake(view.frame.size.width / 8 * 7 - 20, 50, 40, 40)];
    image4.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"iconfont-price" ofType:@"png"]];
    [view addSubview:image4];
    UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(view.frame.size.width / 4 * 3, 90, view.frame.size.width / 4, 40)];
    [view addSubview:label4];
    [label4 release];
    label4.textColor = [UIColor lightGrayColor];
    [label4 setFont:[UIFont systemFontOfSize:15.0]];
    label4.textAlignment = NSTextAlignmentCenter;
    label4.text = self.dic[@"price"];
}

#pragma mark -
#pragma mark 创建scroll
- (void)createScroll
{
    _scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 380, self.view.frame.size.width, self.view.frame.size.height - 380)];
    [self.view addSubview:_scroll];
    [_scroll release];
    
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 80, 80)];
    [_scroll addSubview:imageview];
    [imageview release];
    NSURL *url = [NSURL URLWithString:self.actDic[@"logo"]];
    NSLog(@"%@", url);
    [imageview sd_setImageWithURL:url];
    
    UILabel *rightUpLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, self.view.frame.size.width - 100, 60)];
    [_scroll addSubview:rightUpLabel];
    [rightUpLabel release];
    rightUpLabel.text = self.actDic[@"name"];
    rightUpLabel.numberOfLines = 0;
    [rightUpLabel setFont:[UIFont systemFontOfSize:20]];
    
    UILabel *rightMiddleLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 60, self.view.frame.size.width - 100, 20)];
    [_scroll addSubview:rightMiddleLabel];
    [rightMiddleLabel release];
    rightMiddleLabel.text = self.actDic[@"time"];
    [rightMiddleLabel setFont:[UIFont systemFontOfSize:14.0]];
    
    UILabel *rightDownLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 80, self.view.frame.size.width - 100, 20)];
    [_scroll addSubview:rightDownLabel];
    [rightDownLabel release];
    rightDownLabel.text = self.actDic[@"areaDetail"];
    rightDownLabel.numberOfLines = 0;
    [rightDownLabel setFont:[UIFont systemFontOfSize:14.0]];
    rightDownLabel.textColor = [UIColor grayColor];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    self.navigationItem.title = @"详情";
    [self createScroll];
    [self createLunBo];
//    [self createView];
    [self createMiddleView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
